package com.uxhao.oss.utils;

import com.uxhao.commonutils.util.YamlAndPropertySourceFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * 常量读取工具类
 * @author uxhao
 * @date 2021/1/9 20:47
 */
//当项目自己启动时，有一个接口，Spring加载后，执行这个接口的一个方法
@Component
@PropertySource(value = {"classpath:dev-key.yml"},factory = YamlAndPropertySourceFactory.class)
public class ConstantPropertiesUtils implements InitializingBean {
    //oss服务器地址
    @Value("${aliyun.oss.file.endpoint}")
    private String endpoint;

    //accessKey
    @Value("${aliyun.oss.file.keyid}")
    private String keyId;

    //accessKey
    @Value("${aliyun.oss.file.keysecret}")
    private String keySecret;

    //文件夹名
    @Value("${aliyun.oss.file.filehost}")
    private String fileHost;

    @Value("${aliyun.oss.file.bucketname}")
    private String bucketName;

    public static String END_POINT;
    public static String ACCESS_KEY_ID;
    public static String ACCESS_KEY_SECRET;
    public static String BUCKET_NAME;
    public static String FILE_HOST ;


    @Override
    public void afterPropertiesSet() throws Exception {
        END_POINT = endpoint;
        ACCESS_KEY_ID = keyId;
        ACCESS_KEY_SECRET = keySecret;
        BUCKET_NAME = bucketName;
        FILE_HOST = fileHost;
    }
}
